package com.example.smart.adapter.home

import android.app.Activity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.example.lib.extend.setOnDoubleClickListener
import com.example.smart.R
import com.example.smart.base.adapter.BaseRecyclerAdapter
import com.example.smart.base.adapter.BaseViewHolder
import com.example.smart.databinding.ItemBanner1Binding
import com.example.smart.databinding.ItemBanner1MBinding
import com.example.smart.databinding.ItemBanner2Binding
import com.example.smart.databinding.ItemBanner2MBinding
import com.example.smart.utils.DisplayUtils

class MBannerAdapter(val activity: Activity) : BaseRecyclerAdapter<ViewBinding, Int>(activity, mutableListOf(0, 1)) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<ViewBinding> {
        return if (viewType == 0) {
            BaseViewHolder(ItemBanner1MBinding.bind(LayoutInflater.from(context)
                .inflate(R.layout.item_banner1_m, parent, false)))
        } else {
            BaseViewHolder(ItemBanner2MBinding.bind(LayoutInflater.from(context)
                .inflate(R.layout.item_banner2_m, parent, false)))
        }

    }

    override fun onBindView(itemView: ViewBinding, bean: Int, position: Int) {
        if (getItemViewType(position) == 0) {
            with(itemView as ItemBanner1MBinding) {
                itemView.ItemText.setOnDoubleClickListener {
                    DisplayUtils.toAddAnimal(activity)
                }
            }
        } else {
            with(itemView as ItemBanner2MBinding) {
                itemView.ItemButton1.setOnDoubleClickListener {
                    DisplayUtils.toVaccinesDetails(activity)
                }

                itemView.ItemButton2.setOnDoubleClickListener {
                    DisplayUtils.toVaccinesDetails(activity)
                }

                itemView.ItemButton3.setOnDoubleClickListener {
                    DisplayUtils.toVaccinesDetails(activity)
                }

                itemView.ItemButton4.setOnDoubleClickListener {
                    DisplayUtils.toVaccinesDetails(activity)
                }

                itemView.ItemButton5.setOnDoubleClickListener {
                    DisplayUtils.toVaccinesDetails(activity)
                }

                itemView.ItemButton6.setOnDoubleClickListener {
                    DisplayUtils.toVaccinesDetails(activity)
                }
            }
        }
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }
}